<?php
namespace Admin\Controller;

/**
 * 商品类型  type
 */
class TypeController extends CommonController
{
	public function add(){
		if(IS_GET){
			$this->display();
		}else{
			$Model = D("Type");
			$data = $Model->create();
			if(!$data){
				$this->error($this->getError);
			}
			$res = $Model->add($data);
			if(!$res){
				$this->error("添加失败");
			}
			$this->success("添加成功",U("Type/add"));
		}
	}
	public function index(){
		$Model = D("Type");
		$data = $Model->listData();
		if(!$data){
			$this->error($this->getError);
		}
		$this->assign("data",$data);
		$this->display();
	}
	public function dels(){
		$id = intval(I("get.id"));
		if($id <= 0){
			$this->error("参数不对");
		}
		$Model = D("Type");
		$res = $Model->dels($id);
		if(!$res){
			$this->error("删除失败");
		}
		$this->success("删除成功",U("type/index"));
	}
	public function edit(){
		$Model = D("Type");
		if(IS_GET){
			$id = intval(I("get.id"));
			if($id <= 0){
				$this->error("参数错误");
			}
			$data = $Model->findOneById($id);
			if($data === false){
				$this->error("参数错误");
			}
			$this->assign("data",$data);
			$this->display();
		}else{
			$data = $Model->create();
			if(!$data){
				$this->error($this->getError());
			}
			$res = $Model->update($data);
			if(!$res){
				$this->error("修改失败");
			}
			$this->success("修改成功",U("Type/index"));
		}
	}
}